package com.demo2do.fms.admin.entity.search.supplier;

import java.util.Date;
import java.util.Map;

import org.springframework.format.annotation.DateTimeFormat;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;

/**
 *
 * @author houtao
 *
 */
public class AppraisalSearch implements QueryBuilder {
    
    /** 姓名 */
    private String name;

    /** 开始时间 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date beginDate;

    /** 结束时间*/
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endDate;

    /** 创建人 */
    private Long creator;
    
    /** 是否完成 */
    private Boolean finished;
    
    /** 是否是总部创建 */
    private Boolean adminCreate;
    
    /** 所属分区 */
    private String branchId;
    
    /** 所属供方 */
    private Long supplierId;
    
    private QueryOrder queryOrder;

    private QueryFilter queryFilter;

    /**
     * The default constructor
     */
    public AppraisalSearch() {
        queryOrder = new QueryOrder("beginDate", "DESC");
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public QueryFilter getPreparedFilter(boolean refresh) {

        if (queryFilter == null || refresh) {

            queryFilter = new QueryFilter().addLike("name", name)
                                           .addDateTimeBetween("createDate", beginDate, endDate)
                                           .addEquals("creator", creator)
                                           .addEquals("finished", finished)
                                           .addEquals("adminCreate", adminCreate)
                                           .addEquals("branch.id", branchId)
                                           .addEquals("supplier.id", supplierId)
                                           .addEquals("disabled", false);
            
        }
        
        return queryFilter;
        
    }
    
    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
    public QueryOrder getOrder() {
        return queryOrder;
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        String sentence = "FROM Appraisal" + getPreparedFilter(false).whereSentence() + queryOrder.sentence();
        return sentence;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }
    
    /**
     * 
     * @return
     */
    public QueryFilter getFilter(){
        return getPreparedFilter(false);
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the beginDate
     */
    public Date getBeginDate() {
        return beginDate;
    }

    /**
     * @return the endDate
     */
    public Date getEndDate() {
        return endDate;
    }

    /**
     * @return the creator
     */
    public Long getCreator() {
        return creator;
    }

    /**
     * @return the finished
     */
    public Boolean getFinished() {
        return finished;
    }

    /**
     * @return the adminCreate
     */
    public Boolean getAdminCreate() {
        return adminCreate;
    }

    /**
     * @return the branchId
     */
    public String getBranchId() {
        return branchId;
    }

    /**
     * @return the supplierId
     */
    public Long getSupplierId() {
        return supplierId;
    }

    /**
     * @return the queryOrder
     */
    public QueryOrder getQueryOrder() {
        return queryOrder;
    }

    /**
     * @return the queryFilter
     */
    public QueryFilter getQueryFilter() {
        return queryFilter;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param beginDate the beginDate to set
     */
    public void setBeginDate(Date beginDate) {
        this.beginDate = beginDate;
    }

    /**
     * @param endDate the endDate to set
     */
    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    /**
     * @param creator the creator to set
     */
    public void setCreator(Long creator) {
        this.creator = creator;
    }

    /**
     * @param finished the finished to set
     */
    public void setFinished(Boolean finished) {
        this.finished = finished;
    }

    /**
     * @param adminCreate the adminCreate to set
     */
    public void setAdminCreate(Boolean adminCreate) {
        this.adminCreate = adminCreate;
    }

    /**
     * @param branchId the branchId to set
     */
    public void setBranchId(String branchId) {
        this.branchId = branchId;
    }

    /**
     * @param supplierId the supplierId to set
     */
    public void setSupplierId(Long supplierId) {
        this.supplierId = supplierId;
    }

    /**
     * @param queryOrder the queryOrder to set
     */
    public void setQueryOrder(QueryOrder queryOrder) {
        this.queryOrder = queryOrder;
    }

    /**
     * @param queryFilter the queryFilter to set
     */
    public void setQueryFilter(QueryFilter queryFilter) {
        this.queryFilter = queryFilter;
    }
    
}